﻿using LD.Common;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace LD
{
    public partial class FrmPicture : FrmBase
    {
        private ReDrawUI ReDrawUI = new ReDrawUI();
        private int index = 0;
        private string[] path = null;
        public FrmPicture()
        {
            InitializeComponent();
        }

        private void sw_open_Click(object sender, EventArgs e)
        {
            try
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog();
                dialog.Description = "请选择文件路径";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    string filePath = dialog.SelectedPath;
                    path = Directory.GetFiles(filePath);
                    pbFrmImageShow.Image = Image.FromFile(path[0]);
                    index = 0;
                }
            }
            catch
            {
            }
        }

        private void PrePage_Click(object sender, EventArgs e)
        {
            try
            {
                if (path == null) return;
                index--;
                if (index < 0)
                {
                    index = path.Length - 1;
                }
                pbFrmImageShow.Image = Image.FromFile(path[index]);
            }
            catch
            {
            }
        }

        private void FrmPicture_Load(object sender, EventArgs e)
        {
            this.lklab_data.Text = "图片目录:" + AppSettingHelper.GetConfigValue("CCD_PicturePath");
            this.lklab_data.Tag = AppSettingHelper.GetConfigValue("CCD_PicturePath");

            this.Resize += new EventHandler(Frm_Resize);
            ReDrawUI.ControlInitializeSize(this);
        }
        private void Frm_Resize(object sender, EventArgs e)
        {
            ReDrawUI.ControlAutoSize(this);
        }

        private void NextPage_Click(object sender, EventArgs e)
        {
            try
            {
                if (path == null) return;
                index++;
                if (index == path.Length)
                {
                    index = 0;
                }
                pbFrmImageShow.Image = Image.FromFile(path[index]);
            }
            catch
            {
            }
        }

        private void lklab_data_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(this.lklab_data.Tag.ToString());
        }
    }
}
